import re
def get_config(branch):
    class Config:
        filename_pattern = r"C:\Users\ezhechn\workspace\sqrdata\data\javatest\%s"%branch.name + r"\%s\findbugs.html"
    return Config

def get_html(config, component, raw, old_raw, rank, old_rank):
    return str(raw)

def get_rank(config, component, raw):
    p1, p2, p3 = raw
    if p1 == -1:
        return 0.0
    elif p1 + p2 + p3 > 50:
        return 1.0
    elif p1 > 0:
        return 2.0
    elif p2 > 0:
        return 3.0
    elif p3 > 0:
        return 4.0
    else:
        return 5.0

def get_raw(config, component):
    try:
        filename = config.filename_pattern % component.name
        f = open(filename)
        for aLine in f.readlines():
            m = re.search('^<td class="summary-priority-(\d)"(.*>)$', aLine)
            if m is not None:
                priority = int(m.group(1))
                number = m.group(2).replace('/>','>0</td>')[1:-5]
                data = int(number)
                if (priority ==1):
                    p1 = data
                if( priority ==2):
                    p2 = data
                if( priority ==3):
                    p3 = data
                    return p1, p2, p3
    except IOError:
        return -1, -1, -1
    return -1, -1, -1

